package com.example.wxchatdemo.Files;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.wxchatdemo.R;

import java.util.LinkedList;

//适配器
public class FilesShowAdapter extends BaseAdapter {

    private LinkedList<FileListPojo> mData;
    private Context mContext;

    public FilesShowAdapter(LinkedList<FileListPojo> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    public FilesShowAdapter() {
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
     //   System.out.println("下标是："+position);
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.files_layout,parent,false);
        TextView name = (TextView) convertView.findViewById(R.id.name);
        TextView other = (TextView) convertView.findViewById(R.id.other);
        name.setText(mData.get(position).getFileName());
       // other.setText(mData.get(position).getFilePath());
        //如果是图片
        ImageView imageView = (ImageView) convertView.findViewById(R.id.File_imgs);
        String[] imgs=mData.get(position).getFilePath().split("/");
        if (imgs[imgs.length-1].contains(".jpg")||(imgs[imgs.length-1].contains(".png"))){
            //确定是图片
            imageView.setImageURI(Uri.parse(mData.get(position).getFilePath()));
        }
        else{
            imageView.setBackgroundResource(R.mipmap.file_imgs);
        }
        return convertView;
    }


}